classdef ET_PTB_BLOCK_RANDOMIZED < ET_PTB_SIMPLE
    
    properties
        noise_input
        noise_matrix
        seeds_input
        seeds_matrix
    end    
    methods
        
                
        function prepareNoise(self)
            if mod(self.num_blocks,numel(self.noise_input))
                error('Number of noise levels should divide number of blocks');
            end
            self.noise_matrix = ones(self.num_blocks,self.num_trials);
            tmp = repmat(self.noise_input(:),self.num_trials/numel(self.noise_input),self.num_blocks);
            for i = 1:self.num_blocks
               tmp(:,i) =  tmp(randperm(self.num_trials),i);
            end
            self.noise_matrix = tmp;
        end
        function prepareSeeds(self)
            % Generates the seeds 
            if isempty(self.seeds_input)
               self.seeds_matrix = round(rand(self.num_trials,self.num_blocks)*1e6);
            else
               self.seeds_matrix = ones(self.num_trials,self.num_blocks)*round(self.seeds_input(1));
            end
        end
        function stimuli = generateStimuli(self,trial)
            % Generates a function using blocks and trials
            s    = self.noise_matrix(trial);
            seed = self.seeds_matrix(trial);
            % Sets s and seed in a way that arguments can still be fixed.
            stimuli = inline(sprintf( ...
            'feval(inline(''%s'',''x'',''f'',''s'',''seed''),x,f,%0.2f,%i)',...
            char(self.stimuli),s,seed),'x','f'); 
        end

    end

end